package cn.edu.neusoft.zengweidong707.intent;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Intent_Test extends AppCompatActivity {
    private TextView tvRecv;
    private Button btnSend2;
    private EditText etSend;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent__test);

        tvRecv = (TextView)findViewById(R.id.tvRecv);
        btnSend2 = (Button)findViewById(R.id.btnSend2);
        etSend = (EditText)findViewById(R.id.etSend);

        final Intent intent = getIntent();
        String recvMessage = intent.getStringExtra("message");

        tvRecv.setText(recvMessage);

        btnSend2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String message = etSend.getText().toString();
                Intent intent1 = new Intent(Intent_Test.this, MainActivity.class);

                intent1.putExtra("return", message);

                setResult(RESULT_OK, intent1);
                finish();
            }
        });
    }
}
